package com.mrobuy.jd.pic;

import com.gavel.database.SQLExecutor;
import com.google.gson.Gson;
import com.jd.open.api.sdk.JdClient;
import com.jd.open.api.sdk.domain.supplier.ProductManagementService.response.get.ImagePathDto;
import com.jd.open.api.sdk.domain.supplier.ProductManagementService.response.get.ItemPicApplyDto;
import com.jd.open.api.sdk.domain.supplier.ProductManagementService.response.get.ItemPicSkuDto;
import com.jd.open.api.sdk.request.supplier.VcItemPrimaryPicGetRequest;
import com.jd.open.api.sdk.response.supplier.VcItemPrimaryPicGetResponse;
import com.mrobuy.jd.JdClientFactory;
import com.mrobuy.jd.api.Jos;
import com.mrobuy.jd.api.primarypic.PrimaryPicAppliesFindClient;
import com.mrobuy.jd.sdk.request.VcItemPrimaryPicAppliesFindRequest;
import com.mrobuy.jd.sdk.response.VcItemPrimaryPicAppliesFindResponse;
import com.mrobuy.jdvc.entity.VCItemPic;
import com.mrobuy.jdvc.entity.VCPrimaryPicApply;
import com.mrobuy.jdvc.entity.VCProductInfo;
import com.mrobuy.util.IdentifierGen;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * 获取商品主图申请列表
 */
public class VcItemPrimaryPicApplyFind {

    public static void main(String[] args) throws Exception {

        List<VCPrimaryPicApply>  picApplies = load(JdClientFactory.jdClient());

    }

    private static List<VCPrimaryPicApply> load(JdClient client) throws Exception {


        List<VCPrimaryPicApply> applies =  Jos.primaryPicAppliesFindClient(client)
                                                .call();


        if ( applies!=null  ) {

            for (VCPrimaryPicApply result : applies) {
                System.out.println(new Gson().toJson(result));


                VCProductInfo productInfo = null;
                try {
                    productInfo =  SQLExecutor.executeQueryBean("select * from VC_PRODUCT_INFO where WAREID = ? ", VCProductInfo.class, result.getWareId());
                } catch (Exception e) {
                    e.printStackTrace();
                }

                boolean insert =  ( productInfo==null);
                if ( insert ) {
                    productInfo = new VCProductInfo();
                }

                productInfo.setWareId(result.getWareId());
                productInfo.setWareName(result.getName());
                productInfo.setPicApplyId(result.getApplyId());
                productInfo.setApplyTime(result.getApplyTime());

                productInfo.setSaleState(result.getSaleState());
                productInfo.setState(result.getState());
                productInfo.setBrandId(result.getBrandId());
                productInfo.setBrandName(result.getBrandName());
                productInfo.setCategoryId(result.getCategoryId());
                productInfo.setCategoryName(result.getCategoryName());

                if ( insert ) {
                    SQLExecutor.insert(productInfo);
                } else {
                    SQLExecutor.update(productInfo, false);
                }

            }

        }

        return applies;
    }

}
